<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var change = function (a, b) {
      const dp = new Array(a + 1).fill(0);
      dp[0] = 1;
      for (const arr of b) {
        for (let i = arr; i <= a; i++) {
          dp[i] += dp[i - arr];
        }
      }
      return dp[a];
    };
    console.log(change(5, [1, 2, 5]));
  </script>
</body>

</html>